package cn.frh.system.controller;

import cn.frh.basic.util.AjaxResult;
import cn.frh.basic.util.pageList;
import cn.frh.system.domain.Systemdictionarydetail;
import cn.frh.system.query.SystemdictionarydetailQuery;
import cn.frh.system.service.ISystemdictionarydetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description: 字典明细控制层接口
 * @date: 2022年08月19日 ： 9:39
 * @version: ver1.0
 * @email 1739441354@qq.com
 */
@RestController
@RequestMapping("/systemdictionarydetail")
public class SystemdictionarydetailController {
    @Autowired
    private ISystemdictionarydetailService systemdictionarydetailService;

    @GetMapping
    public List<Systemdictionarydetail> loadAll(){
        return systemdictionarydetailService.loadAll();
    }
    @GetMapping("/{id}")
    public Systemdictionarydetail loadById(@PathVariable("id") Long id){
        return systemdictionarydetailService.loadById(id);
    }


    @DeleteMapping("/{id}")
    private AjaxResult remove(@PathVariable("id") Long id){
        try {
            systemdictionarydetailService.remove(id);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"删除失败");
        }
    }
    @PutMapping
    public AjaxResult addOrupdate(@RequestBody Systemdictionarydetail systemdictionarydetail){

        try {
            if(systemdictionarydetail.getId()==null){
                systemdictionarydetailService.save(systemdictionarydetail);

            }else {
                systemdictionarydetailService.update(systemdictionarydetail);
            }
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"操作失败");
        }
    }

    @PatchMapping
    private AjaxResult patchRemove(@RequestBody List<Long> ids){
        try {
            systemdictionarydetailService.patchRemove(ids);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"删除失败");
        }
    }

    @PostMapping
    public pageList<Systemdictionarydetail> query(@RequestBody SystemdictionarydetailQuery systemdictionarydetailQuery){
       return systemdictionarydetailService.queryPage(systemdictionarydetailQuery);
    }


    @GetMapping("/type/{id}")
    public List<Systemdictionarydetail> TypeId(@PathVariable("id") Long id){
        return systemdictionarydetailService.loadByTypeId(id);
    }

}
